#ifndef CODE_PIGEON_H
#define CODE_PIGEON_H

#include "buffer.h"
#include "node.h"


#define CODE_PIGEON_BUFFER_SIZE 128

CMARK_INLINE
static void cmark_html_render_code_pigeon_make_header_id(cmark_node *node, cmark_strbuf *html){
  if ( !node->first_child || node->first_child->type != CMARK_NODE_TEXT ){
    // 这说明没有标题
    return;
  }
  node = node->first_child;

  char buffer[CODE_PIGEON_BUFFER_SIZE] = " id=\"";
  int buffer_index = 5;
  int space_char_flag = 0;

  unsigned char* title = node->as.literal.data;

  // 为了清除掉标题中的空格字符
  do{
    if( *title == ' ' || *title == '\t'){
      if(space_char_flag){
        continue;
      }
      space_char_flag = 1;
      buffer[buffer_index++] = '-';
      continue;
    }

    space_char_flag = 0;
    buffer[buffer_index++] = *title;
  }while( *(++title) );

  buffer[buffer_index++] = '\"';
  buffer[buffer_index] = '\0';

  cmark_strbuf_puts(html, buffer);
}


#endif